Skip to content

Add workflow to auto-close linked playground items when PRs close#12439

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-workflow-for-auto-close
Draft

Add workflow to auto-close linked playground items when PRs close#12439
Copilot wants to merge 2 commits intomainfrom
copilot/add-workflow-for-auto-close

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

Adds test-scenario-cleanup.yml workflow to automatically clean up test scenario PRs/issues in dotnet/aspire-playground when a PR closes in the main repository. Only closes items tagged with auto-close label.

Triggers

  • Automatic: When any PR is closed
  • Manual: Comment /test-scenario-cleanup on a PR

Implementation

  • Searches PR body and comments for playground references via GraphQL
  • Filters by auto-close label before closing
  • Uses GH_PLAYGROUND_TOKEN secret for playground authentication (same pattern as test-scenario.yml)
  • Handles both issues and PRs, skips already-closed or unlabeled items
  • Posts summary comment on manual invocation

Example

PR contains:

Fixes https://github.com/dotnet/aspire-playground/issues/123
See https://github.com/dotnet/aspire-playground/pull/456

On PR close:

Original prompt

I want you to create a workflow that triggers when a PR is closed that gets the list of PRs and issues on the dotnet/aspire-playground repository that are linked to the PR that was just closed and closes them.

However only close the PRs and issues in the dotnet/aspire-playground repo linked where they have the "auto-close" tag applied.

In order to authenticate to the dotnet/aspire-playground repo you will need to use the GH_PLAYGROUND_TOKEN secret. Review the test-scenario.yml workflow for how it is structured around authentication and permissions.

The new workflow should be called test-scenario-cleanup.yml and it should also be able to be triggered by the comment /test-scenario-cleanup for when we want to clean up the PRs and issues in the playground repo.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
Copilot AI changed the title [WIP] Add workflow for auto-closing linked PRs and issues Add workflow to auto-close linked playground items when PRs close Oct 28, 2025
Copilot AI requested a review from mitchdenny October 28, 2025 08:35
@mitchdenny
Copy link
Member

@radical input?

@mitchdenny mitchdenny requested a review from radical October 28, 2025 11:09
@mitchdenny mitchdenny added the area-engineering-systems infrastructure helix infra engineering repo stuff label Oct 28, 2025
@mitchdenny mitchdenny added this to the 13.0 milestone Oct 28, 2025
echo "PR number: $PR_NUMBER"
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT

- name: Download and install GitHub CLI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to install this manually? The runners will have the cli installed.

echo "Cleanup complete. Closed $CLOSED_COUNT item(s)."

- name: Comment on PR with cleanup summary
if: steps.cleanup.outputs.closed_count > 0 && github.event_name == 'issue_comment'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to comment even when closed_count == 0, just so the user knows what happened.

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ steps.get_pr_number.outputs.pr_number }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PR_NUMBER="${{ steps.get_pr_number.outputs.pr_number }}"
set -euo pipefail # Exit on error, undefined vars, pipe failures
PR_NUMBER="${{ steps.get_pr_number.outputs.pr_number }}"

runs-on: ubuntu-latest
env:
REPO_OWNER: dotnet
REPO_NAME: aspire-playground
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to PLAYGROUND_REPO_NAME to avoid confusion when reading the code?

QUERY='query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
closingIssuesReferences(first: 100) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to be using the results from matching the issues. Maybe jq could be used to extract the information from the result?

Comment on lines +122 to +125
# Find playground issue/PR references in format: https://github.com/dotnet/aspire-playground/issues/123 or /pull/123
PLAYGROUND_REFS=$(echo -e "$PR_BODY\n$COMMENTS" | \
grep -oP "https://github\.com/${REPO_OWNER}/${REPO_NAME}/(issues|pull)/\K\d+" | \
sort -u)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to be using the results from matching the issues with closingIssuesReferences. Maybe jq could be used to extract the information from the result?

@joperezr joperezr modified the milestones: 13.0, 13.1 Nov 13, 2025
@joperezr joperezr modified the milestones: 13.1, 13.2 Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-engineering-systems infrastructure helix infra engineering repo stuff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants